//
//  UIDevice+DDAdd.m
//  AFNetworking
//
//  Created by 许龙 on 2020/3/25.
//

#import "UIDevice+DDAdd.h"

@implementation UIDevice (DDAdd)

- (BOOL)isIPhoneXSeries {
    BOOL iPhoneXSeries = NO;
    Class cls = NSClassFromString(@"UIApplication");
    if (cls && [cls respondsToSelector:@selector(sharedApplication)]) {
        if (@available(iOS 11.0, *)) {
            UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
            UIWindow *mainWindow = [[application delegate] window];
            if (mainWindow.safeAreaInsets.bottom > 0.0) {
                iPhoneXSeries = YES;
            }
        }
    }
    return iPhoneXSeries;
}

+ (UIDeviceType)getDeviceType {
    CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
    if (fabs((double)screenHeight - (double)480) < DBL_EPSILON) {
        return UIDeviceIS_IPHONE_4S;
    } else if (fabs((double)screenHeight - (double)568) < DBL_EPSILON) {
        return UIDeviceIS_IPHONE_5;
    } else if (fabs((double)screenHeight - (double)667) < DBL_EPSILON) {
        return UIDeviceIS_IPHONE_6;
    } else if (fabs((double)screenHeight - (double)736) < DBL_EPSILON) {
        return UIDeviceIS_IPHONE_6P;
    }
    return UIDeviceIS_IPHONE_6;
}
@end
